<?php
namespace app\index\model;

use think\Db;
use think\Model;

class UserInfo extends Model
{
    protected $table = 'quick_user_';

    /*获取表名*/
    public function getTable($agent_id)
    {
        return $this->table . intval(substr($agent_id,-2));
    }

    /*获取单条记录*/
    public function getOne($where,$field='*',$agent_id)
    {
        $info = Db::table($this->getTable($agent_id))->where($where)->field($field)->findOrEmpty();
        return $info;
    }

    /*获取列表记录*/
    public function getList($where, $field = '*',$page = 1, $pageSize = 100, $orderBy = [], $groupBy = '')
    {
        $list = Db::table($this->getTable($where['agent_id']))->where($where)->field($field)
            ->page($page,$pageSize)->order($orderBy)->group($groupBy)->select();

        return $list ? $list : [];
    }

    /*获取总记录数*/
    public function getTotalNumber($where)
    {
        $count = Db::table($this->getTable($where['agent_id']))->where($where)->count('id');
        return $count;
    }

    /*更新记录*/
    public function updateRecord($where,$data,$agent_id)
    {
        $res = Db::table($this->getTable($agent_id))->where($where)->update($data);
        return $res >= 0 ? true : false;
    }

    /*添加记录*/
    public function insertRecord($data,$agent_id)
    {
        $res = Db::table($this->getTable($agent_id))->insertGetId($data);
        return $res > 0 ? $res : false;
    }

}